Shared Chat
Model: Default

Refactor onUpdate Prop

July 6, 2023
You are a commit message generator for the JavaScript project. I will give you a code change from the JavaScript repository and you tell me its commit message. The output format is one sentence. The code change is ```diff diff --git a/modules/Router.js b/modules/Router.js index dd2787480b..df196c43c7 100644 --- a/modules/Router.js +++ b/modules/Router.js @@ -52,7 +52,7 @@ class Router extends Component { } componentWillMount() { - let { history, children, routes, parseQueryString, stringifyQuery } = this.props + let { history, children, routes, onUpdate, parseQueryString, stringifyQuery } = this.props let createHistory = history ? () => history : createHashHistory this.history = useRoutes(createHistory)({ @@ -65,7 +65,7 @@ class Router extends Component { if (error) { this.handleError(error) } else { - this.setState(state, this.props.onUpdate) + this.setState(state, () => onUpdate && onUpdate.call(this, state)) } }) } diff --git a/modules/__tests__/Router-test.js b/modules/__tests__/Router-test.js index 7974321a65..58c74113bd 100644 --- a/modules/__tests__/Router-test.js +++ b/modules/__tests__/Router-test.js @@ -425,4 +425,21 @@ describe('Router', function () { }).toThrow('error fixture') }) }) + + describe('onUpdate', function () { + it('should pass the router state as the first argument', function (done) { + + function onUpdate(state) { + expect(state).toEqual(this.state) + done() + } + + render(( + <Router history={createHistory('/')} onUpdate={onUpdate}> + <Route path="/" component={Child} /> + </Router> + ), node) + }) + + }) }) ```
ChatGPTChatGPT

Refactor Router's onUpdate prop to use a callback function and pass the router state as the first argument.